//
//  RefreshBtn.m
//  meiyinxiang
//
//  Created by apple on 25/10/2017.
//  Copyright © 2017 hbjApple. All rights reserved.
//

#import "RefreshBtn.h"
@interface RefreshBtn()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (assign, nonatomic)  BOOL isDone;

@end
@implementation RefreshBtn
+ (id)loadNibWithRefreshBtn{
    UINib *nib = [UINib nibWithNibName:@"RefreshBtn" bundle:nil];
    return [[nib instantiateWithOwner:self options:nil]lastObject];
}
- (void)addRefreshTarget:(nullable id)target action:(SEL _Nullable )action forControlEvents:(UIControlEvents)controlEvents{
    [self addTarget:target action:action forControlEvents:controlEvents];
}

#pragma mark -PrivateMethod
- (void)addRefreshAnimation{
    self.isDone = !self.isDone;
    NSLog(@"self.isDone %d",self.isDone);
    [self rotate360DegreeWithImageView];
}
-(void)rotate360DegreeWithImageView {
    CABasicAnimation * rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; //让其在z轴旋转
    rotationAnimation.toValue = [NSNumber numberWithFloat: -M_PI * 2.0 ];//旋转角度
    rotationAnimation.duration = 2; //旋转周期
    rotationAnimation.cumulative = YES;//旋转累加角度
    rotationAnimation.repeatCount = 1;//旋转次数
    [self.imageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
